<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="java,springboot,thymeleaf," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="前言本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf，实现一个简单的用户增删改查示例工程。事先说明，有三个项目，两个是单独整合的，一个是将它们整合在一起的。如需其中一个，只需看相应部分的介绍即可。若需工程源代码，可以直接跳到底部，通过链接下载工程代码。 SpringBoot整合Jsp开发准备环境要求JDK: 1.7或以上SQL: MySql 这里我们需">
<meta name="keywords" content="java,springboot,thymeleaf">
<meta property="og:type" content="article">
<meta property="og:title" content="SpringBoot整合Jsp和Thymeleaf(附工程)">
<meta property="og:url" content="http://yoursite.com/2018/07/11/pancm88/index.html">
<meta property="og:site_name" content="虚无境的博客">
<meta property="og:description" content="前言本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf，实现一个简单的用户增删改查示例工程。事先说明，有三个项目，两个是单独整合的，一个是将它们整合在一起的。如需其中一个，只需看相应部分的介绍即可。若需工程源代码，可以直接跳到底部，通过链接下载工程代码。 SpringBoot整合Jsp开发准备环境要求JDK: 1.7或以上SQL: MySql 这里我们需">
<meta property="og:image" content="https://img-blog.csdn.net/20180711215130477?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180711222017759?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180711222043667?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180711222055618?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180711224255884?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180711224902476?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180711224912627?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180711224924297?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180717185344591?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180717185921157?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:image" content="https://img-blog.csdn.net/20180717185945150?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
<meta property="og:updated_time" content="2018-08-19T14:25:44.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="SpringBoot整合Jsp和Thymeleaf(附工程)">
<meta name="twitter:description" content="前言本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf，实现一个简单的用户增删改查示例工程。事先说明，有三个项目，两个是单独整合的，一个是将它们整合在一起的。如需其中一个，只需看相应部分的介绍即可。若需工程源代码，可以直接跳到底部，通过链接下载工程代码。 SpringBoot整合Jsp开发准备环境要求JDK: 1.7或以上SQL: MySql 这里我们需">
<meta name="twitter:image" content="https://img-blog.csdn.net/20180711215130477?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/07/11/pancm88/"/>






  <title>SpringBoot整合Jsp和Thymeleaf(附工程) | 虚无境的博客</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?39c177d10f6e05ddfa113e02139b9c1c";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">虚无境的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/07/11/pancm88/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="虚无境">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/xuwujing.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="虚无境的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">SpringBoot整合Jsp和Thymeleaf(附工程)</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-07-11T22:57:57+08:00">
                2018-07-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/java/" itemprop="url" rel="index">
                    <span itemprop="name">java</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <script src="\assets\js\APlayer.min.js"> </script><h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>本篇文章主要讲述<strong>SpringBoot</strong>整合<strong>Jsp</strong>以及<strong>SpringBoot</strong>整合<strong>Thymeleaf</strong>，实现一个简单的用户增删改查示例工程。事先说明，有三个项目，两个是单独整合的，一个是将它们整合在一起的。如需其中一个，只需看相应部分的介绍即可。若需工程源代码，可以直接跳到底部，通过链接下载工程代码。</p>
<h2 id="SpringBoot整合Jsp"><a href="#SpringBoot整合Jsp" class="headerlink" title="SpringBoot整合Jsp"></a>SpringBoot整合Jsp</h2><h3 id="开发准备"><a href="#开发准备" class="headerlink" title="开发准备"></a>开发准备</h3><p><strong>环境要求</strong><br><strong>JDK</strong>: 1.7或以上<br><strong>SQL</strong>: MySql</p>
<p>这里我们需要在mysql中建立一张用户表，用于存储用户的信息。<br><strong>数据库脚本如下:</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">CREATE TABLE `t_user` (</div><div class="line">  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT &apos;自增id&apos;,</div><div class="line">  `name` varchar(10) DEFAULT NULL COMMENT &apos;姓名&apos;,</div><div class="line">  `age` int(2) DEFAULT NULL COMMENT &apos;年龄&apos;,</div><div class="line">  `password` varchar(24) NOT NULL COMMENT &apos;密码&apos;,</div><div class="line">  PRIMARY KEY (`id`)</div><div class="line">) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8</div></pre></td></tr></table></figure></p>
<p>新建好表之后，我们再来创建工程。<br>我们的这个工程是通过maven创建一个普通的web工程。<br>创建好工程之后，我们需要下载相应的jar包，然后再来进行相关的开发。<br>这些jar包我们在pom.xml文件中添加springBoot和Jsp相关的jar即可。<br>相关的注释以及写在其中了，这里就不在过多讲述了。<br><strong>Maven依赖如下:</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div></pre></td><td class="code"><pre><div class="line">&lt;dependencies&gt;</div><div class="line"> 		&lt;!-- Spring Boot Web 依赖 核心 --&gt;</div><div class="line">	&lt;dependency&gt;</div><div class="line">		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; </div><div class="line">		&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;</div><div class="line">	&lt;/dependency&gt;</div><div class="line"></div><div class="line">	&lt;!-- Spring Boot 热部署 class文件之后会自动重启 --&gt;</div><div class="line">	&lt;dependency&gt;</div><div class="line">		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</div><div class="line">		&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;</div><div class="line">		&lt;optional&gt;true&lt;/optional&gt;</div><div class="line">	&lt;/dependency&gt;</div><div class="line">	&lt;!-- Spring Boot Test 依赖 --&gt;</div><div class="line">	&lt;dependency&gt;</div><div class="line">		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</div><div class="line">		&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;</div><div class="line">		&lt;scope&gt;test&lt;/scope&gt;</div><div class="line">	&lt;/dependency&gt;</div><div class="line"> 		</div><div class="line"> 		&lt;!-- Spring Boot JPA --&gt;</div><div class="line">	&lt;dependency&gt;</div><div class="line">		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</div><div class="line">		&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;</div><div class="line">	&lt;/dependency&gt;</div><div class="line"> 		</div><div class="line"> 		  &lt;!-- Spring Boot Mybatis 依赖 --&gt;</div><div class="line">       &lt;dependency&gt;</div><div class="line">           &lt;groupId&gt;org.mybatis.spring.boot&lt;/groupId&gt;</div><div class="line">           &lt;artifactId&gt;mybatis-spring-boot-starter&lt;/artifactId&gt;</div><div class="line">           &lt;version&gt;$&#123;mybatis-spring-boot&#125;&lt;/version&gt;</div><div class="line">       &lt;/dependency&gt;</div><div class="line">       </div><div class="line">       &lt;dependency&gt;</div><div class="line">           &lt;groupId&gt;mysql&lt;/groupId&gt;</div><div class="line">           &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;</div><div class="line">       &lt;/dependency&gt;</div><div class="line">       </div><div class="line"> 		&lt;!--fastjson 相关jar --&gt;</div><div class="line">	&lt;dependency&gt;</div><div class="line">		&lt;groupId&gt;com.alibaba&lt;/groupId&gt;</div><div class="line">		&lt;artifactId&gt;fastjson&lt;/artifactId&gt;</div><div class="line">		&lt;version&gt;$&#123;fastjson&#125;&lt;/version&gt;</div><div class="line">	&lt;/dependency&gt;</div><div class="line"> 		</div><div class="line"> 				&lt;!--JSP 依赖  --&gt;</div><div class="line"> 		&lt;!-- servlet依赖. --&gt;  </div><div class="line"> 		&lt;dependency&gt;  </div><div class="line">           &lt;groupId&gt;javax.servlet&lt;/groupId&gt;  </div><div class="line">           &lt;artifactId&gt;jstl&lt;/artifactId&gt;</div><div class="line">       &lt;/dependency&gt;  </div><div class="line">       </div><div class="line">       &lt;dependency&gt;  </div><div class="line">           &lt;groupId&gt;javax.servlet&lt;/groupId&gt;  </div><div class="line">           &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;</div><div class="line">           &lt;scope&gt;provided&lt;/scope&gt;  </div><div class="line">       &lt;/dependency&gt;  </div><div class="line">      </div><div class="line">       &lt;!-- tomcat的支持.--&gt;</div><div class="line">	&lt;dependency&gt;</div><div class="line">		&lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;</div><div class="line">		&lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;</div><div class="line">		&lt;scope&gt;provided&lt;/scope&gt;</div><div class="line">	&lt;/dependency&gt;    </div><div class="line"> &lt;/dependencies&gt;</div></pre></td></tr></table></figure>
<p>相关的Jar包下载完毕之后，我们再来确认项目的工程结构。<br>首先是后台相关包说明:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">src/main/java</div><div class="line">com.pancm.web - Controller 层</div><div class="line">com.pancm.dao - 数据操作层 DAO</div><div class="line">com.pancm.pojo- 实体类</div><div class="line">com.pancm.service - 业务逻辑层</div><div class="line">Application - 应用启动类</div><div class="line"></div><div class="line">src/main/resources</div><div class="line">application.properties - 应用配置文件，应用启动会自动读取配置</div></pre></td></tr></table></figure></p>
<p>前端的相关文件存放说明:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">src/main/webapp</div><div class="line">WEB-INF - web.xml web相关的核心配置</div><div class="line">WEB-INF/jsp - JSP文件的存放路径</div></pre></td></tr></table></figure></p>
<p>整体工程结构图:<br><img src="https://img-blog.csdn.net/20180711215130477?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p>工程结构确认之后，我们再来添加相应的配置。<br>只需在<strong>application.properties</strong>  添加相应的配置即可。<br>数据源的配置和之前的差不多，需要注意的是<strong>Jsp</strong>的相关配置。<br>由于springBoot默认的支持的模版是<strong>Thymeleaf</strong>，所以这里我们需要进行相应的更改。</p>
<p><strong>配置如下:</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">## 编码</div><div class="line">banner.charset=UTF-8</div><div class="line">server.tomcat.uri-encoding=UTF-8</div><div class="line">spring.http.encoding.charset=UTF-8</div><div class="line">spring.http.encoding.enabled=true</div><div class="line">spring.http.encoding.force=true</div><div class="line">spring.messages.encoding=UTF-8</div><div class="line">## 端口</div><div class="line">server.port=8088</div><div class="line"></div><div class="line">## 数据源</div><div class="line">spring.datasource.url=jdbc:mysql://localhost:3306/springBoot?useUnicode=true&amp;characterEncoding=utf8</div><div class="line">spring.datasource.username=root</div><div class="line">spring.datasource.password=123456</div><div class="line">spring.datasource.driver-class-name=com.mysql.jdbc.Driver</div><div class="line"></div><div class="line">## JSP配置</div><div class="line"># 页面默认前缀</div><div class="line">spring.mvc.view.prefix=/WEB-INF/jsp/</div><div class="line"># 响应页面默认后缀</div><div class="line">spring.mvc.view.suffix=.jsp</div></pre></td></tr></table></figure></p>
<h3 id="代码编写"><a href="#代码编写" class="headerlink" title="代码编写"></a>代码编写</h3><p>其实这里的代码和之前文章讲述的基本一致，唯一有点区别的是，这里我是用JPA实现对数据库进行操作的(也就是顺便说下JPA这个框架的使用)。</p>
<p>首先是实体类，这里因为用了JPA，所以和之前的有点不同，添加了一些注解。<br><strong>Entity</strong>：表示这是个实体类。<br><strong>Table</strong>：该实体类映射的数据表名。<br><strong>Column</strong>：指定该字段的属性，nullable 表示是否非空，unique 表示是否是唯一。</p>
<p><strong>那么实体类的代码如下:</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">@Entity</div><div class="line">@Table(name = &quot;t_user&quot;)</div><div class="line">public class User &#123;</div><div class="line">	</div><div class="line">	 /** 编号 */</div><div class="line">	 @Id</div><div class="line">	 @GeneratedValue</div><div class="line">	 private Long id;</div><div class="line">	 /** 姓名 */</div><div class="line">	 @Column(nullable = false, unique = true)</div><div class="line">	 private String name;</div><div class="line">	 /** 密码*/</div><div class="line">	 @Column(nullable = false)</div><div class="line">	 private String password;</div><div class="line">	 /** 年龄 */</div><div class="line">	 @Column(nullable = false)</div><div class="line">	 private Integer age;</div><div class="line">	</div><div class="line">	//getter和setter略</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>由于用的是JPA，dao层这块只需继承<strong>JpaRepository</strong>该类即可，需要指定实体类和主键类型。<br><strong>dao层代码如下:</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">@Mapper</div><div class="line">public interface UserDao extends JpaRepository&lt;User, Long&gt;&#123;</div><div class="line">	</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>业务层这块和之前一样调用即可，虽然用的是JPA，但是方法也是很简单的，新增和修改就用save，删除就是delete，findOne就是通过ID查找，findAll就是查询所有等等。</p>
<p><strong>services代码如下:</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div></pre></td><td class="code"><pre><div class="line">@Service</div><div class="line">public class UserServiceImpl implements UserService &#123;</div><div class="line"></div><div class="line">	@Autowired</div><div class="line">    private UserDao userDao;</div><div class="line">	</div><div class="line">	</div><div class="line">	@Override</div><div class="line">	public boolean addUser(User user) &#123;</div><div class="line">		boolean flag=false;</div><div class="line">		try&#123;</div><div class="line">			userDao.save(user);</div><div class="line">			flag=true;</div><div class="line">		&#125;catch(Exception e)&#123;</div><div class="line">			System.out.println(&quot;新增失败!&quot;);</div><div class="line">			e.printStackTrace();</div><div class="line">		&#125;</div><div class="line">		return flag;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	@Override</div><div class="line">	public boolean updateUser(User user) &#123;</div><div class="line">		boolean flag=false;</div><div class="line">		try&#123;</div><div class="line">			userDao.save(user);</div><div class="line">			flag=true;</div><div class="line">		&#125;catch(Exception e)&#123;</div><div class="line">			System.out.println(&quot;修改失败!&quot;);</div><div class="line">			e.printStackTrace();</div><div class="line">		&#125;</div><div class="line">		return flag;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	@Override</div><div class="line">	public boolean deleteUser(Long id) &#123;</div><div class="line">		boolean flag=false;</div><div class="line">		try&#123;</div><div class="line">			userDao.delete(id);</div><div class="line">			flag=true;</div><div class="line">		&#125;catch(Exception e)&#123;</div><div class="line">			System.out.println(&quot;删除失败!&quot;);</div><div class="line">			e.printStackTrace();</div><div class="line">		&#125;</div><div class="line">		return flag;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	@Override</div><div class="line">	public User findUserById(Long id) &#123;</div><div class="line">		return userDao.findOne(id);</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	@Override</div><div class="line">	public List&lt;User&gt; findAll() &#123;</div><div class="line">		return userDao.findAll();</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>到了控制层这块，这里提供还是提供接口给Jsp进行调用，不过这里类的注解就不能用之前的<strong>RestController</strong>这个注解，这个注解以json的格式返回数据，但是我们有时返回的时候需要跳转界面，所以应该使用<strong>Controller</strong>这个注解。如果想在某个方法中返回的数据格式是json的话，在该方法上加上<strong>ResponseBody</strong>这个注解即可。</p>
<p><strong>控制层代码如下:</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div></pre></td><td class="code"><pre><div class="line">@Controller</div><div class="line">public class UserRestController &#123;</div><div class="line">		@Autowired</div><div class="line">		private UserService userService;</div><div class="line"> </div><div class="line">		@RequestMapping(&quot;/hello&quot;)</div><div class="line">	    public String hello() &#123;</div><div class="line">	        return &quot;hello&quot;;</div><div class="line">	    &#125;</div><div class="line">		</div><div class="line">		@RequestMapping(&quot;/&quot;)</div><div class="line">	    public String index() &#123;</div><div class="line">	        return &quot;redirect:/list&quot;;</div><div class="line">	    &#125;</div><div class="line">		</div><div class="line">		</div><div class="line">	    @RequestMapping(&quot;/list&quot;)</div><div class="line">	    public String list(Model model) &#123;</div><div class="line">	    	System.out.println(&quot;查询所有&quot;);</div><div class="line">	        List&lt;User&gt; users=userService.findAll();</div><div class="line">	        model.addAttribute(&quot;users&quot;, users);</div><div class="line">	        return &quot;user/list&quot;;</div><div class="line">	    &#125;</div><div class="line"></div><div class="line">	    @RequestMapping(&quot;/toAdd&quot;)</div><div class="line">	    public String toAdd() &#123;</div><div class="line">	        return &quot;user/userAdd&quot;;</div><div class="line">	    &#125;</div><div class="line"></div><div class="line">	    @RequestMapping(&quot;/add&quot;)</div><div class="line">	    public String add(User user) &#123;</div><div class="line">	        userService.addUser(user);</div><div class="line">	        return &quot;redirect:/list&quot;;</div><div class="line">	    &#125;</div><div class="line"></div><div class="line">	    @RequestMapping(&quot;/toEdit&quot;)</div><div class="line">	    public String toEdit(Model model,Long id) &#123;</div><div class="line">	        User user=userService.findUserById(id);</div><div class="line">	        model.addAttribute(&quot;user&quot;, user);</div><div class="line">	        return &quot;user/userEdit&quot;;</div><div class="line">	    &#125;</div><div class="line"></div><div class="line">	    @RequestMapping(&quot;/edit&quot;)</div><div class="line">	    public String edit(User user) &#123;</div><div class="line">	        userService.updateUser(user);</div><div class="line">	        return &quot;redirect:/list&quot;;</div><div class="line">	    &#125;</div><div class="line"></div><div class="line"></div><div class="line">	    @RequestMapping(&quot;/toDelete&quot;)</div><div class="line">	    public String delete(Long id) &#123;</div><div class="line">	        userService.deleteUser(id);</div><div class="line">	        return &quot;redirect:/list&quot;;</div><div class="line">	    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h3 id="功能测试"><a href="#功能测试" class="headerlink" title="功能测试"></a>功能测试</h3><p>后端代码介绍就到这里了，至于前端JSP的代码就不在多说了(主要原因是界面写得太丑了…），我们直接启动项目，查看效果。<br>启动项目，在浏览器上输入:<a href="http://localhost:8088/list" target="_blank" rel="external">http://localhost:8088/list</a><br><strong>主界面:</strong><br><img src="https://img-blog.csdn.net/20180711222017759?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p>添加一条数据之后的界面:<br><img src="https://img-blog.csdn.net/20180711222043667?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p><img src="https://img-blog.csdn.net/20180711222055618?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p>其它的修改和删除也能实现，这里就在一一不贴图了。<br>springBoot整合 Jsp到这就结束了。</p>
<h2 id="SringBoot整合Thymeleaf"><a href="#SringBoot整合Thymeleaf" class="headerlink" title="SringBoot整合Thymeleaf"></a>SringBoot整合Thymeleaf</h2><p>该工程参考:<a href="http://www.ityouknow.com/springboot/2017/09/23/spring-boot-jpa-thymeleaf-curd.html" target="_blank" rel="external">http://www.ityouknow.com/springboot/2017/09/23/spring-boot-jpa-thymeleaf-curd.html</a></p>
<h3 id="Thymeleaf介绍"><a href="#Thymeleaf介绍" class="headerlink" title="Thymeleaf介绍"></a>Thymeleaf介绍</h3><p>Thymeleaf是个模板引擎，可以用于Web与非Web应用，它可以XML/XHTML/HTML5， JavaScript, CSS ,甚至文本文件。</p>
<h3 id="Thymeleaf的使用"><a href="#Thymeleaf的使用" class="headerlink" title="Thymeleaf的使用"></a>Thymeleaf的使用</h3><p>Thymeleaf这块个人使用不太熟练，这个也不是本篇文章主要讲述的内容，详细的可以查看官方文档。<br><a href="https://www.thymeleaf.org/documentation.html" target="_blank" rel="external">https://www.thymeleaf.org/documentation.html</a></p>
<h3 id="开发准备-1"><a href="#开发准备-1" class="headerlink" title="开发准备"></a>开发准备</h3><p>基本和上面的SringBoot整合Jsp差不多，这里就不再赘述了。</p>
<p>由于SpringBoot默认的模版引擎就是Thymeleaf，所以Maven 依赖这块只需要在原先的springBoot项目添加Thymeleaf的依赖就行。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"> &lt;dependency&gt;</div><div class="line">           &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</div><div class="line">           &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;</div><div class="line">&lt;/dependency&gt;</div></pre></td></tr></table></figure>
<p><strong>application.properties</strong>  配置这块，可以和之前的项目基本一致，需要注意的也只有<strong>spring.thymeleaf.cache</strong>配置，为false的时候是关闭Thymeleaf的缓存，更改界面之后会自动重启然后生效。</p>
<p>SringBoot整合Thymeleaf和SringBoot整合Jsp有个比较大的不同是，Thymeleaf的资源文件是放在<strong>src/main/resources</strong>目录下，Jsp的是放在<strong>src/main/webapp</strong>目录下。其中resources目录下的的static目录用于放置静态内容，比如css、js、jpg图片等。templates目录用于放置项目使用的页面模板，也就是<strong>.html</strong>文件。</p>
<p>它的项目结构图如下:<br><img src="https://img-blog.csdn.net/20180711224255884?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p>代码基本和SringBoot整合Jsp一致，这里就不在赘述了。</p>
<h3 id="功能测试-1"><a href="#功能测试-1" class="headerlink" title="功能测试"></a>功能测试</h3><p>启动该项目，在浏览器输入:<a href="http://localhost:8085" target="_blank" rel="external">http://localhost:8085</a><br><strong>主界面:</strong><br><img src="https://img-blog.csdn.net/20180711224902476?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p>修改用户数据之后的:<br><img src="https://img-blog.csdn.net/20180711224912627?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p><img src="https://img-blog.csdn.net/20180711224924297?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p>其它的功能也是可以实现的，这里就不再过多贴图了。<br>springBoot整合 Thymeleaf到这就结束了。</p>
<h2 id="SpringBoot整合Jsp和Thymeleaf"><a href="#SpringBoot整合Jsp和Thymeleaf" class="headerlink" title="SpringBoot整合Jsp和Thymeleaf"></a>SpringBoot整合Jsp和Thymeleaf</h2><p><strong>注:</strong>这个是后来新加的一个项目。<br>SpringBoot单独整合<strong>Jsp</strong>和<strong>Thymeleaf</strong>都还好，没出现什么问题。但是在一起之后，就有了改变，因为SpringBoot默认的模板引擎是<strong>Thymeleaf</strong>，加上<strong>JSP</strong>之后，JSP的模板引擎并不会生效。但是如果想用JSP模板，此时的禁用到<strong>Thymeleaf</strong>，虽然可以通过多态更改配置实现，但是感觉太过麻烦了。于是研究了一下，找到了共存的方法。</p>
<p><strong>和前面来两个项目区别如下：</strong></p>
<ol>
<li><p>之前的<strong>Jsp</strong>和<strong>Thymeleaf</strong>配置都是在<strong>application.properties</strong><br> 文件中，这里我将它们的配置改到代码中获取。</p>
<p>2.之前<strong>Thymeleaf</strong>相关文件是放在 <strong>src/main/resources</strong> 目录下，这里移动到WEB-INF目录下，和之前的jsp文件夹同级。</p>
</li>
</ol>
<p>3.增加一个控制层，严格区分访问<strong>Jsp</strong>和<strong>Thymeleaf</strong>的路径。访问<strong>Jsp</strong>的路径前缀加上<strong>jsp</strong>，访问<strong>Thymeleaf</strong>前缀加上<strong>templates</strong>。</p>
<p><strong>那么新增的配置代码如下:</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div></pre></td><td class="code"><pre><div class="line">@Configuration</div><div class="line">@EnableWebMvc</div><div class="line">@ComponentScan</div><div class="line">public class WebConfig extends WebMvcConfigurerAdapter &#123;</div><div class="line">	</div><div class="line">	   @Bean</div><div class="line">       public ViewResolver viewResolver() &#123;</div><div class="line">           InternalResourceViewResolver resolver = new InternalResourceViewResolver();</div><div class="line">           resolver.setPrefix(&quot;/WEB-INF/&quot;);</div><div class="line">           resolver.setSuffix(&quot;.jsp&quot;);</div><div class="line">           resolver.setViewNames(&quot;jsp/*&quot;);</div><div class="line">           resolver.setOrder(2);</div><div class="line">           return resolver;</div><div class="line">       &#125;</div><div class="line"></div><div class="line">       @Bean</div><div class="line">       public ITemplateResolver templateResolver() &#123;</div><div class="line">           SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();</div><div class="line">           templateResolver.setTemplateMode(&quot;HTML5&quot;);</div><div class="line">           templateResolver.setPrefix(&quot;/WEB-INF/&quot;);</div><div class="line">           templateResolver.setSuffix(&quot;.html&quot;);</div><div class="line">           templateResolver.setCharacterEncoding(&quot;utf-8&quot;);</div><div class="line">           templateResolver.setCacheable(false);</div><div class="line">           return templateResolver;</div><div class="line">       &#125;</div><div class="line"></div><div class="line">       @Bean</div><div class="line">       public SpringTemplateEngine templateEngine() &#123;</div><div class="line">           SpringTemplateEngine templateEngine = new SpringTemplateEngine();</div><div class="line">           templateEngine.setTemplateResolver(templateResolver());</div><div class="line">           return templateEngine;</div><div class="line">       &#125;</div><div class="line"></div><div class="line">       @Bean</div><div class="line">       public ThymeleafViewResolver viewResolverThymeLeaf() &#123;</div><div class="line">           ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();</div><div class="line">           viewResolver.setTemplateEngine(templateEngine());</div><div class="line">           viewResolver.setCharacterEncoding(&quot;utf-8&quot;);</div><div class="line">           viewResolver.setViewNames(new String[]&#123;&quot;thymeleaf/*&quot;&#125;);</div><div class="line">           viewResolver.setOrder(1);</div><div class="line">           return viewResolver;</div><div class="line">       &#125;</div><div class="line"></div><div class="line">       @Override</div><div class="line">       public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) &#123;</div><div class="line">           configurer.enable();</div><div class="line">       &#125;</div><div class="line"></div><div class="line">       @Override</div><div class="line">       public void addResourceHandlers(ResourceHandlerRegistry registry) &#123;</div><div class="line">           super.addResourceHandlers(registry);</div><div class="line">       &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>项目的结构图如下:<br><img src="https://img-blog.csdn.net/20180717185344591?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<h3 id="功能测试-2"><a href="#功能测试-2" class="headerlink" title="功能测试"></a>功能测试</h3><p>在浏览器输入:<a href="http://localhost:8089/list" target="_blank" rel="external">http://localhost:8089/list</a><br>查看<strong>Thymeleaf</strong>模板的界面<br><img src="https://img-blog.csdn.net/20180717185921157?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p>在浏览器输入:<a href="http://localhost:8089/list2" target="_blank" rel="external">http://localhost:8089/list2</a><br>查看<strong>JSP</strong>模板的界面<br><img src="https://img-blog.csdn.net/20180717185945150?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FhendzeHBjbQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述"></p>
<p>可以看到已经成功整合了</p>
<h2 id="其它"><a href="#其它" class="headerlink" title="其它"></a>其它</h2><p>关于SpringBoot整合Jsp和Thymeleaf 到这里就结束了。<br>SpringBoot整合Jsp的项目工程地址:<br><a href="https://github.com/xuwujing/springBoot-study/tree/master/springboot-jsp-jpa" target="_blank" rel="external">https://github.com/xuwujing/springBoot-study/tree/master/springboot-jsp-jpa</a><br>SpringBoot整合Thymeleaf的项目工程地址:<br><a href="https://github.com/xuwujing/springBoot-study/tree/master/springboot-thymeleaf" target="_blank" rel="external">https://github.com/xuwujing/springBoot-study/tree/master/springboot-thymeleaf</a><br>SpringBoot整合Jsp和Thymeleaf的项目工程地址:<br><a href="https://github.com/xuwujing/springBoot-study/tree/master/springboot-jsp-thymeleaf" target="_blank" rel="external">https://github.com/xuwujing/springBoot-study/tree/master/springboot-jsp-thymeleaf</a></p>
<p>原创不易，如果感觉不错，希望给个推荐！您的支持是我写作的最大动力！<br>版权声明:<br>作者：虚无境<br>博客园出处：<a href="http://www.cnblogs.com/xuwujing" target="_blank" rel="external">http://www.cnblogs.com/xuwujing</a><br>CSDN出处：<a href="http://blog.csdn.net/qazwsxpcm" target="_blank" rel="external">http://blog.csdn.net/qazwsxpcm</a>　　　　<br>个人博客出处：<a href="http://www.panchengming.com" target="_blank" rel="external">http://www.panchengming.com</a> </p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>
     
    <div>
	 +
	  
<div style="text-align:center;color: #ccc;font-size:14px;">
------ 本文结束 ------</div>
<br/>
<div style="border: 1px solid black">
<div style="margin-left:10px">
<span style="font-weight:blod">版权声明</span>
<!-- <img src="/images/xuwujing.png" > -->
<br/>
<p style="font-size: 10px;line-height: 30px"><a href="http://www.panchengming.com/" style="color:#258FC6">xuwujing's Notes</a> by <a href="http://www.panchengming.com/" style="color:#258FC6">ChengMing Pan</a> is licensed under a <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/" style="color:#258FC6">Creative Commons BY-NC-ND 4.0 International License</a>.<br/>
由<a href="http://www.panchengming.com/" style="color:#258FC6">虚无境</a>创作并维护的<a href="http://www.panchengming.com/" style="color:#258FC6">xuwujing's Notes</a>博客采用<a href="https://creativecommons.org/licenses/by-nc-nd/4.0/" style="color:#258FC6">创作共用保留署名-非商业-禁止演绎4.0国际许可证</a>。<br/>
本文首发于<a href="http://www.panchengming.com/" style="color:#258FC6">xuwujing's Notes</a> 博客（ <a href="http://www.panchengming.com/" style="color:#258FC6">http://www.panchengming.com/</a> ），版权所有，侵权必究。</p>
</div>
</div>

	
	</div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/java/" rel="tag"># java</a>
          
            <a href="/tags/springboot/" rel="tag"># springboot</a>
          
            <a href="/tags/thymeleaf/" rel="tag"># thymeleaf</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/07/07/pancm87/" rel="next" title="Java进阶篇设计模式之一 ----- 单例模式">
                <i class="fa fa-chevron-left"></i> Java进阶篇设计模式之一 ----- 单例模式
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/07/17/pancm89/" rel="prev" title="SpringBoot整合Netty并使用Protobuf进行数据传输(附工程)">
                SpringBoot整合Netty并使用Protobuf进行数据传输(附工程) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/xuwujing.png"
               alt="虚无境" />
          <p class="site-author-name" itemprop="name">虚无境</p>
           
              <p class="site-description motion-element" itemprop="description">The way of the future!</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">136</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">30</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">59</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/xuwujing" target="_blank" title="github">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  github
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://blog.csdn.net/qazwsxpcm?viewmode=list" target="_blank" title="csdn">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  csdn
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://home.cnblogs.com/u/xuwujing/" target="_blank" title="cnblogs">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  cnblogs
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.woainia.site/" title="woainia" target="_blank">woainia</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://cmsblogs.com/" title="chenssy" target="_blank">chenssy</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://italker.imisty.cn" title="xiaowu" target="_blank">xiaowu</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SpringBoot整合Jsp"><span class="nav-number">2.</span> <span class="nav-text">SpringBoot整合Jsp</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#开发准备"><span class="nav-number">2.1.</span> <span class="nav-text">开发准备</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代码编写"><span class="nav-number">2.2.</span> <span class="nav-text">代码编写</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#功能测试"><span class="nav-number">2.3.</span> <span class="nav-text">功能测试</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SringBoot整合Thymeleaf"><span class="nav-number">3.</span> <span class="nav-text">SringBoot整合Thymeleaf</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Thymeleaf介绍"><span class="nav-number">3.1.</span> <span class="nav-text">Thymeleaf介绍</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Thymeleaf的使用"><span class="nav-number">3.2.</span> <span class="nav-text">Thymeleaf的使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#开发准备-1"><span class="nav-number">3.3.</span> <span class="nav-text">开发准备</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#功能测试-1"><span class="nav-number">3.4.</span> <span class="nav-text">功能测试</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SpringBoot整合Jsp和Thymeleaf"><span class="nav-number">4.</span> <span class="nav-text">SpringBoot整合Jsp和Thymeleaf</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#功能测试-2"><span class="nav-number">4.1.</span> <span class="nav-text">功能测试</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#其它"><span class="nav-number">5.</span> <span class="nav-text">其它</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">虚无境</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
 | 
本站总访问量<span id="busuanzi_value_site_pv"></span>次
 | 
本站访客数<span id="busuanzi_value_site_uv"></span>人次
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=857896&auto=0&height=66"></iframe>



        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
